const app = getApp()

Page({
  data: {
    start:0,
    like:0,
    truename:'新用户',
    myname:'',
    preson:'',
    gt:'',
    ht:'',
    modalshow:'',
    helpshow:'',
    goodshow:'',
    avatarUrl: "https://6c79-lyr-4gvx88rj047e3d79-1308815870.tcb.qcloud.la/1681224885000.png",
    theme: wx.getSystemInfoSync().theme,
    lb:[
      {img:'https://6c79-lyr-4gvx88rj047e3d79-1308815870.tcb.qcloud.la/1679454374000.png?sign=18702eff75084004e8938b4701947cde&t=1679454386',
      value:'编辑个人信息',kind:'show'},
      // {img:'https://6c79-lyr-4gvx88rj047e3d79-1308815870.tcb.qcloud.la/1679454321000.png?sign=0e651524179d7709e0a74cd1f71e4195&t=1679454332',
      // value:'设置账号和密码'},  
      {img:'https://6c79-lyr-4gvx88rj047e3d79-1308815870.tcb.qcloud.la/1679454480000.png?sign=6f23238e584bd55edaa897ec906baa1b&t=1679454489',
      value:'好评鼓励',kind:'good'},
      {img:'https://6c79-lyr-4gvx88rj047e3d79-1308815870.tcb.qcloud.la/1679379960000.png?sign=9bb0630a94b5534d35712a6ed9632598&t=1679379989',
      value:'帮助与反馈',kind:'help'},
      {img:'https://6c79-lyr-4gvx88rj047e3d79-1308815870.tcb.qcloud.la/1679379964000.png?sign=d16c6606d9c506bd611215b7d1200e51&t=1679379977',
      value:'关于我们',kind:'forus'},
      ]
  },
  onLoad(options) {

  },
  getimg:function(e){
    var that  =this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
        const tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths[0])
        that.setData({
          imgsrc:tempFilePaths[0]
        })
      }
    })
  },
  show(){
    this.setData({
      modalshow:'true',
      person:false
    })
  },
  
  cancelM(){
    this.setData({
      modalshow:'',
    })
  },
  
  iname:function(e){
    var that = this
    if(e.detail.value ==''){
      that.setData({
        person:false
      })
    }else{
      that.setData({
        myname:e.detail.value,
        person:true
      })
    }
    
    console.log(e.detail.value)
  },
  confirmM(e){
    var that = this
    if(this.data.person==true){
      that.setData({
        modalshow:'',
        truename:this.data.myname
      })
    }else{
      wx.showToast({
        title: '请输入昵称',
        icon:'none'
      })
    }
  },
  forus(){
    wx.navigateTo({
      url: '/pages/aboutus/aboutus',
    })
  },
  help(){
    this.setData({
      helpshow:'true',
      ht:false
    })
  },
  helpbtn(){
    this.setData({
      helpshow:'',
    })
  },
  helpbtn1(){
    var that = this
    if(this.data.ht==true){
      that.setData({
        helpshow:'',
      })
      wx.showToast({
        title: '感谢您的反馈',
      })
    }else{
      wx.showToast({
        title: '请留下您的意见',
        icon:'none'
      })
    }
    
  },

  helptext:function(e){
    var that = this
    if(e.detail.value != ''){
      that.data.ht = true
    }
    console.log(e.detail.value)
  },

  good(){
    this.setData({
      goodshow:'true',
    })
    this.data.gt = false
  },
  goodbtn(){
    this.setData({
      goodshow:'',
    })
  },
  goodbtn1(){
    if(this.data.gt == true){
      wx.showToast({
        title: '谢谢您的支持',
      })    
      this.setData({
        goodshow:'',
      })
    }else{
     wx.showToast({
       title: '请留下您的意见',
       icon:'none'
     })
    }

  },
  goodtext:function(e){
    var that = this
    if(e.detail.value != ''){
      that.data.gt = true
    }
    console.log(e.detail.value)
  },
  // changeName(){
  //   wx.showModal({
  //     cancelColor: 'cancelColor',
  //     title:'修改昵称',
  //     editable:true,
  //     placeholderText:'请输入昵称'
  //   })
  // },

  onChooseAvatar(e) {
    const {avatarUrl} = e.detail
    this.setData({
      avatarUrl
    })
    console.log(e)
  },

  toHistory: function() {
    console.log("to history"), wx.navigateTo({
        url: "/pages/history/history"
    });
  },
  tolike(){
    wx.navigateTo({
      url: '/pages/liketie/liketie',
    })
  },
  tostart(){
    wx.navigateTo({
      url: '/pages/starttie/starttie',
    })
  },
  onShareAppMessage: function () {

  },
  
  imageClick(){
    var that = this;
    wx.chooseImage({  //从本地相册选择图片或使用相机拍照
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有

      success: function (res) {

        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths
        var uid = that.data.uid
        wx.uploadFile({
          url: '',
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
            uid
          },
          success: function (res) {
            const data = res.data
            const obj = JSON.parse(data); 
            const image = obj.image
            that.setData({
              image 
            })
          }
        })
      }
    })
  }


  
})